import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../provider/chatdetailprovider.dart';
import '../../provider/_providers.dart';


class ChatdetailInputUI extends ConsumerWidget {

  ChatdetailInputUI({super.key,required this.chatDetailProvider});

  ChangeNotifierProvider<ChatDetailProvider> chatDetailProvider;


  TextEditingController textController = TextEditingController();

  var focusNode = FocusNode();

  submitChat(WidgetRef ref) {
    if (textController.text.trim().isEmpty) return;


    ref.read(chatDetailProvider).chat(textController.text);

    textController.text = "";
    focusNode.requestFocus();
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {

    return Consumer(
        builder: (context, ref, child)
    {

      return Align(
        alignment: Alignment.bottomLeft,
        child: Container(
          padding: EdgeInsets.only(left: 10, bottom: 10, top: 10),
          height: 60,
          width: double.infinity,
          color: Colors.white,
          child: Row(
            children: <Widget>[
              GestureDetector(
                onTap: () {},
                child: Container(
                  height: 30,
                  width: 30,
                  decoration: BoxDecoration(
                    color: Colors.lightBlue,
                    borderRadius: BorderRadius.circular(30),
                  ),
                  child: Icon(
                    Icons.add,
                    color: Colors.white,
                    size: 20,
                  ),
                ),
              ),
              SizedBox(
                width: 15,
              ),
              Expanded(
                child: TextField(
                  controller: textController,
                  focusNode: focusNode,
                  onSubmitted: (value) {
                    submitChat(ref);
                  },
                  decoration: InputDecoration(
                      hintText: "请输入...",
                      hintStyle: TextStyle(color: Colors.black54),
                      border: InputBorder.none),
                ),
              ),
              SizedBox(
                width: 15,
              ),
              FloatingActionButton(
                onPressed: () {
                  submitChat(ref);
                },
                child: Icon(
                  Icons.send,
                  color: Colors.white,
                  size: 18,
                ),
                backgroundColor: Colors.blue,
                elevation: 0,
              ),
            ],
          ),
        ),
      );
    });


  }
}
